import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 模板
const Default = () => import('../layouts/Default.vue')

const Home = () => import('../views/home/index.vue')
const Policy = () => import('../views/policy/index.vue')
const CoreValue = () => import('../views/corevalue/index.vue')
const Dvb = () => import('../views/dvb/index.vue')
const Oic = () => import('../views/oic/index.vue')
const OxSFC = () => import('../views/oxsfc/index.vue')
const Bangor = () => import('../views/bangor/index.vue')
const Dundee = () => import('../views/dundee/index.vue')
const Montfort = () => import('../views/montfort/index.vue')
const Greenwich = () => import('../views/greenwich/index.vue')
const Jacobs = () => import('../views/jacobs/index.vue')
const Application = () => import('../views/application/index.vue')
const Agents = () => import('../views/agents/index.vue')
const Download = () => import('../views/download/index.vue')
const Pwu = () => import('../views/pwu/index.vue')
const Map = () => import('../views/map/index.vue')
// const Info = () => import('../views/infoOpen/Info.vue')
// const About = () => import('../views/aboutCompany/About.vue')
// const Law = () => import('../views/regulations/Law.vue')
// const Vip = () => import('../views/memberServe/Vip.vue')
// const Profiles = () => import('../views/profiles/Profiles.vue')
// const PropsTradeIndex = () => import('../views/propsTrade/index.vue')
// const PropsTrade = () => import('../views/propsTrade/PropsTrade.vue')
// const PropsTradeInfo = () => import('../views/propsTrade/TradeInfo.vue')
// const TradeEnroll = () => import('../views/propsTrade/TradeEnroll.vue')
// const Login = () => import('../page/login/Login.vue')
// const Register = () => import('../page/register/Regis.vue')



// const Err404 = () => import('../page/error/404.vue')

const routes = [
  {
    path: '/', name: 'Default', component: Default, redirect: '/index',
    children: [
      { path: 'index', name: 'index', component: Home ,meta: { title: '首页' },},
      { path: 'policy', name: 'policy', component: Policy ,meta: { title: '隐私条款' },},
      { path: 'corevalue', name: 'corevalue', component: CoreValue ,meta: { title: '核心价值观' },},
      { path: 'dvb', name: 'dvb', component: Dvb ,meta: { title: 'DVB' },},
      { path: 'oic', name: 'oic', component: Oic ,meta: { title: 'OIC' },},
      { path: 'oxsfc', name: 'oxsfc', component: OxSFC ,meta: { title: 'OxSFC' },},
      { path: 'bangor', name: 'bangor', component: Bangor ,meta: { title: '班戈大学' },},
      { path: 'dundee', name: 'dundee', component: Dundee ,meta: { title: '邓迪大学' },},
      { path: 'montfort', name: 'montfort', component: Montfort ,meta: { title: '德蒙福特大学' },},
      { path: 'greenwich', name: 'greenwich', component: Greenwich ,meta: { title: '格林威治大学' },},
      { path: 'jacobs', name: 'jacobs', component: Jacobs ,meta: { title: '雅各布大学' },},
      { path: 'application', name: 'application', component: Application ,meta: { title: '申请' },},
      { path: 'agents', name: 'agents', component: Agents ,meta: { title: '介绍' },},
      { path: 'download', name: 'download', component: Download ,meta: { title: '下载' },},
      { path: 'pwu', name: 'pwu', component: Pwu ,meta: { title: '联系合作' },},
      { path: 'map', name: 'map', component: Map ,meta: { title: '网站地图' },},
      /*{ path: 'search', name: 'search', component: Search },
      {
        path: 'propsTrade', name: 'propsTrade', component: PropsTradeIndex,
        children: [
          { path: '', name: 'propsTrade', component: PropsTrade },
          { path: 'tradeinfo', name: 'propsTrade', component: PropsTradeInfo },
          { path: 'tradeenroll', name: 'propsTrade', component: TradeEnroll },
        ]
      },
      { path: 'info', name: 'info', component: Info },
      { path: 'vip', name: 'vip', component: Vip },
      { path: 'law', name: 'law', component: Law },
      { path: 'about', name: 'about', component: About },
      { path: 'profiles', name: 'profiles', component: Profiles },

      { path: "login", name: "login", component: Login, },
      { path: "register", name: "register", component: Register, },*/
    ]
  },
  // { path: '*', name: 'err404', component: Err404 }
]

const router = new VueRouter({
  mode: 'hash',
  routes,
  scrollBehavior (to, from, savedPosition) {

    return { x: 0, y: 0 }
  }
})


router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
